{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 购物车程序项目\n",
    "\n",
    "   #### 要求：\n",
    "   * 1、运行程序后，让用户输入支付宝余额，然后打印我们的商品列表给用户\n",
    "   * 2、让用户输入商品编号进行商品购买\n",
    "   * 3、用户选择商品后，检查用户的余额是否够，若够则直接扣款，不够则提醒用户\n",
    "   * 4、用户可以随时退出购买，退出时打印用户已购买的商品和支付宝余额"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "invalid syntax (<ipython-input-17-dc82e49cd2be>, line 10)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  File \u001b[1;32m\"<ipython-input-17-dc82e49cd2be>\"\u001b[1;36m, line \u001b[1;32m10\u001b[0m\n\u001b[1;33m    Alipay = int(input(\"请输入您的余额:\"))\u001b[0m\n\u001b[1;37m    ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n"
     ]
    }
   ],
   "source": [
    "# 商品的数据信息\n",
    "goods_list = [\n",
    "    [#商品名称，商品价格]\n",
    "    ['珍珠奶茶',7],\n",
    "    ['大杯珍珠奶茶',8.5],\n",
    "    ['加大杯珍珠奶茶',9.5],\n",
    "    ['桶装珍珠奶茶',20],\n",
    "]\n",
    "#用户输入 使用input， input使用，结果是一个字符串\n",
    "Alipay = int(input(\"请输入您的余额:\"))   \n",
    "#循环遍历列表，将商品信息按照一定格式输出\n",
    "#一定格式；商品编号；xxx，商品名称；xxx，商品价格；xxx\n",
    "print(\"------请输入编号，欢迎选购------\")\n",
    "for i in range(len(goods_list)):#range会根据商品列表的长度变化而变化\n",
    "    print(\"商品编号:%s,商品名称:%s,商品价格:%s\"%(i,goods_list[i][0],,goods_list[i][1]))\n",
    "    \n",
    "#2.让用户输入商品编号进行商品购买\n",
    "#1.用户输入的内容是否符合规范（用户买的东西有没有）？\n",
    "    \n",
    "#思考： 用户除了输入数值外，有没有可能输入的不是数值\n",
    "choice =int input(\"请输入正确的购买商品的编号:\")\n",
    "if choice.isdigit():#isdigit 判断字符串里面的内容是否是数值\n",
    "    choice = int(choice)\n",
    "if choice > len(good_list):\n",
    "#b. 如果没有该商品，返回没有\n",
    "    print(\"您选的商品不存在\")\n",
    "#a.  如果有判断余额是否够，用户金额Alipay 商品的金额good_list[chioce][1]\n",
    "if Alipay>good_list[choice][1]:\n",
    "    # 用户余额够 1.增加该商品到用户购物车 2.扣除余额\n",
    "        \n",
    "    user_shopping_car.append(good_list[choice])\n",
    "    Alipay = Alipay-good_list[choice][1]\n",
    "    print(\"【%s】已加入您的购物车，您的账户余额还有:%s元\"%(good_list[choice][0],Alipay))\n",
    "    else:\n",
    "    print(\"您的余额不足，请更换支付方式\")\n",
    "    elif choice == \"q\":\n",
    "    #用户退出购买\n",
    "    print(\"用户购物车:\",user_shopping_car)\n",
    "    print(\"您的余额还有:\",Alipay)\n",
    "    break\n",
    "    else:\n",
    "    printprint(\"您的余额还有:\", ！！！)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
